Ext.applyIf(String.prototype, {
			/**
			 * 去两端空格
			 * 
			 * @return {String} 却掉空格的字符串
			 */
			trim : function() {
				return this.replace(/(^\s*)|(\s*$)/g, "");
			}
		});
Ext.applyIf(Date.prototype, {
			/**
			 * 
			 * @param {string}
			 *            format 格式，eg:format="YYYY-MM-dd hh:mm:ss";
			 * @return {string} 指定格式的日期
			 */
			format : function(format) {
				var o = {
					"M+" : this.getMonth() + 1, // month
					"d+" : this.getDate(), // day
					"h+" : this.getHours(), // hour
					"m+" : this.getMinutes(), // minute
					"s+" : this.getSeconds(), // second
					"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
					"S" : this.getMilliseconds()
					// 毫秒
				}
				if (/(y+)/.test(format)) {
					format = format.replace(RegExp.$1,
							(this.getFullYear() + "").substr(4
									- RegExp.$1.length));
				}
				for (var k in o) {
					if (new RegExp("(" + k + ")").test(format)) {
						format = format.replace(RegExp.$1,
								RegExp.$1.length == 1 ? o[k] : ("00" + o[k])
										.substr(("" + o[k]).length));
					}
				}
				return format;
			}
		});
Ext.namespace("Hroze");
Ext.namespace("Ext.ux");
/**
 * @author zhwang
 * @class Hroze.util
 * @static 单例
 * @version 1.0 2010-08-17
 */
Hroze.util = function() {
	var debug = false;
	/**
	 * ajax 配置
	 */
	var cfg = {
		autoAlert : true,
		autoEval : true,
		method : 'POST'
	};
	return {
		/**
		 * @description do nothing
		 */
		emptyFn : function() {
		},
		/**
		 * @description 页面卸载前调用的函数，用于提示用户（火狐和IE）
		 * @param {function}
		 *            checkFn 页面关闭时将调用本函数，返回的字符串会提示用户
		 */
		onUnload : function(checkFn) {
			window.onbeforeunload = function(event) {
				var value = checkFn();
				if (value) {
					if (Ext.isIE) {
						window.event.returnValue = value;
					} else {
						event.returnValue = value;
					}
				}
			}
		},
		/**
		 * @param {Object}
		 *            o 同 Ext.Ajax.request(o),o中增加了autoAlert，和autoEval参数
		 */
		request : function(o) {
			Ext.applyIf(o, cfg);
			var tmp = {};
			Ext.apply(tmp, o);
			Ext.apply(o, {
						success : function(response) {
							var result = response.responseText;
							var bool = true;
							try {
								result = Ext.decode(result);
								bool = false;;
								if (result.success) {
									if (typeof result.success == 'string') {
										if (result.success == "true") {
											result.success = true;
										} else {
											result.success = false;
										}
									}
								}
								if (result.msg && o.autoAlert) {
									alert(result.msg);
								}
								if (result.script && o.autoEval) {
									eval(result.script);
								}
								if (Ext.isFunction(tmp.success)) {
									if (tmp.scope) {
										var fn = tmp.success.createDelegate(
												tmp.scope, [response, result,
														true]);
										fn();
									} else {
										var fn = tmp.success;
										fn(response, result, true);
									}
								}
							} catch (e) {
								// 当解码失败时，说明返回值不是json,直接返回的html
								if (bool) {
									if (Ext.isFunction(tmp.success)) {
										if (tmp.scope) {
											var fn = tmp.success
													.createDelegate(tmp.scope,
															[response, result,
																	false]);
											fn();
										} else {
											var fn = tmp.success;
											fn(response, result, false);
										}
									}
								}
								if (debug) {
									console.info(e);
								}
							}
						},
						failure : function(response) {
							var result = response.responseText;
							if (Ext.isFunction(tmp.failure)) {
								if (tmp.scope) {
									var fn = tmp.failure.createDelegate(
											tmp.scope, [result, false]);
									fn();
								} else {
									var fn = tmp.failure;
									fn(result, false);
								}
							}
						}
					});
			Ext.Ajax.request(o);

		},
		/**
		 * @description 获得预定义的reader，zhwang专用
		 * @param {Array}
		 *            info 用来定义record的数组
		 * @return {Ext.data.JsonReader} 会犯
		 */
		getReader : function(info, id) {
			return new Ext.data.JsonReader({
						totalProperty : 'totalProperty',
						root : 'data',
						successProperty : 'success',
						id : (id ? id : "")
					}, info);
		},
		/**
		 * @description 读取cookie
		 * @param {string}
		 *            name cookie的名字
		 */
		getCookie : function(name) {
			var arr = document.cookie.match(new RegExp("(^| )" + name
					+ "=([^;]*)(;|$)"));
			if (arr != null)
				return unescape(arr[2]);
			return null;
		},
		/**
		 * @description 设置cookie
		 * @param {String}
		 *            name cookie名字
		 * @param {String}
		 *            value cookie值
		 */
		setCookie : function(name, value) {
			var Days = 30;
			var exp = new Date(); // new Date("December 31, 9998");
			exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
			document.cookie = name + "=" + escape(value) + ";expires="
					+ exp.toGMTString();
		},
		/**
		 * @description 删除cookie
		 * @param {String}
		 *            name cookie名
		 */
		delCookie : function(name) {
			var exp = new Date();
			exp.setTime(exp.getTime() - 1);
			var cval = getCookie(name);
			if (cval != null)
				document.cookie = name + "=" + cval + ";expires="
						+ exp.toGMTString();
		},
		/**
		 * @description 重新载入图像
		 * @param {Mixed}
		 *            el img元素的id或者img的dom节点
		 */
		reloadImage : function(el) {
			var img_cc = Ext.getDom(el);
			var url = this.decodeURL(img_cc.src);
			url.args._a_b_cd = Math.random();
			img_cc.src = this.encodeURL(url.url, url.args);
		},
		/**
		 * @description 解码地址
		 * @param {string}
		 *            url 地址
		 * @return {object} 格式：
		 * 
		 * <pre>
		 * <code>
		 *  
		 * { url : &quot;http://...&quot;, //地址 
		 *   args:{
		 *   name1:'value1',
		 *   name2:'name2'
		 *   } 
		 *  }
		 * </code>
		 * </pre>
		 */
		decodeURL : function(url) {
			var arr = url.split('?');
			var args = {};
			if (arr.length > 1) {
				var pairs = arr[1].split('&');
				for (var i = 0; i < pairs.length; i++) {
					var argarr = pairs[i].split('=');
					if (argarr.length == 2) {
						args[argarr[0]] = argarr[1];
					}
				}
			}
			return {
				url : arr[0],
				args : args
			}
		},
		/**
		 * @param {object}
		 *            args 必须是一个对象, 例如: {key:'value'}
		 * @param {string}
		 *            url 地址（可选）
		 */
		encodeURL : function(args, url) {
			if (url) {
				var last = url.charAt(url.length);
				if (last != "?" && last != "&") {
					if (url.indexOf('?') < 0) {
						url = url + '?';
					} else {
						url = url + '&';
					}
				}
			}
			if (!url)
				url = "";
			for (var p in args) {
				if (!Ext.isEmpty(args[p]))
					url = url + p + '=' + args[p] + '&';
			}
			if (url & url.charAt(url.length - 1) == '&') {
				url = url.substring(0, url.length - 1);
			}
			return url;
		},
		/**
		 * @description 截取多余字符串并用...代替
		 * @param {string}
		 *            str 字符
		 * @param {int}
		 *            length 显示长度
		 */
		more : function(str, length) {
			return str & str.length > length
					? (str.substring(0, length) + "...")
					: str;
		},
		/**
		 * 加入收藏
		 */
		addFavorite : function(sURL, sTitle) {
			try {
				window.external.addFavorite(sURL, sTitle);
			} catch (e) {
				try {
					window.sidebar.addPanel(sTitle, sURL, "");
				} catch (e) {
					alert("加入收藏失败，请使用Ctrl+D进行添加");
				}
			}
		},
		/**
		 * 设为首页
		 */
		setHome : function(obj, vrl) {
			try {
				obj.style.behavior = 'url(#default#homepage)';
				obj.setHomePage(vrl);
			} catch (e) {
				if (window.netscape) {
					try {
						netscape.security.PrivilegeManager
								.enablePrivilege("UniversalXPConnect");
					} catch (e) {
						alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
					}
					var prefs = Components.classes['@mozilla.org/preferences-service;1']
							.getService(Components.interfaces.nsIPrefBranch);
					prefs.setCharPref('browser.startup.homepage', vrl);
				}
			}
		},
		/**
		 * 判断是否正整数
		 * 
		 * @param {String}
		 *            str 字符串
		 */
		isN : function(str) {
			var reg = /^\d{1,10}$/;
			return reg.test(str);
		}
	}
}();
Ext.ux.util = Hroze.util;
var $util = Hroze.util;